package com.diy.common.baseModel;

import java.io.Serializable;
import java.util.List;

/**
 * Created by GY on 2015/11/22.
 */
public class Paging<T> implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    private int pageNumber;
    private int pageSize;
    private long pageCount;
    private long totalCount;
    private List<T> itemList;

    public Paging() {
    }

    public Paging(int pageNumber, int pageSize, long totalCount, List<T> itemList) {
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.itemList = itemList;

        //--------------- modify by Hans ---------------
        if (pageSize != 0) {
            if (totalCount % pageSize == 0) {
                pageCount = totalCount / pageSize;
            } else {
                pageCount = totalCount / pageSize + 1;
            }
        }
        //--------------- modify by Hans ---------------
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public int getPageSize() {
        return pageSize;
    }

    public long getPageCount() {
        return pageCount;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public boolean hasPrevPage() {
        return pageNumber > 1 && pageNumber <= pageCount;
    }

    public boolean hasNextPage() {
        return pageNumber < pageCount;
    }

    public boolean isFirstPage() {
        return pageNumber == 1;
    }

    public boolean isLastPage() {
        return pageNumber == pageCount;
    }

    public List<T> getItemList() {
        return itemList;
    }
}